package com.aurora.app.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.aurora.app.dao.ThingImageDao;
import com.aurora.app.entity.HelpImage;
import com.aurora.app.entity.ThingImage;
import com.aurora.app.entity.ThingStoryImage;
import com.aurora.app.enums.FakeDelete;
import com.aurora.base.dao.BaseDao;
import com.aurora.base.dto.Order;
import com.aurora.base.service.BaseService;

@Service
public class ThingImageService extends BaseService<ThingImage> {

	@Resource
	private ThingImageDao baseDao;
	@Override
	public BaseDao<ThingImage> getBaseDao() {
		// TODO Auto-generated method stub
		return this.baseDao;
	}
	
	/**
	 * 获取最新创建的那一福图片
	 * @param thingId
	 * @return
	 */
	public ThingImage  getFirstImageByThingId(String thingId){
		Order order = new Order();
		order.put("createTime", Order.DESC);
		List<ThingImage> imgList =this.baseDao.list(order,0,1,"o.isDelete = ? and o.thing.id =? ", FakeDelete.NODELETE,thingId);
		if(imgList!=null&!imgList.isEmpty()){
			return imgList.get(0);
		}
		return null;
	}
	
	
	/**
	 * 获取前size个thingImage
	 * @param thingId
	 * @param size
	 * @return
	 */
	public List<ThingImage>  getBeforeImageByThingId(String thingId,int size){
		Order order = new Order();
		order.put("createTime", Order.DESC);
		List<ThingImage> imgList =this.baseDao.list(order,0,size,"o.isDelete = ? and o.thing.id =? ", FakeDelete.NODELETE,thingId);
		return imgList;
	}
	
	public List<ThingImage> getListByThingId(String thingId){
		return this.baseDao.list("o.isDelete = 0 and o.thing.id = ?", thingId);
	}

}
